package com.itheima.day08_api;

import java.util.ArrayList;

public class Demo5_ArrayList {
    public static void main(String[] args) {
        //1.创建一个arraylist集合对象
        ArrayList<String> list = new ArrayList<>();
        //2.添加元素
        list.add("hello");
        list.add("hello");
        list.add("world");
        list.add("java");
        System.out.println("list = " + list);
        //3.添加元素，索引为2，添加元素javaee，索引为2的元素被覆盖，索引为3的元素后移，
        list.add(2,"javaee");
        System.out.println("list = " + list);
        //4.获取集合中指定索引位置的元素
        String rs = list.get(2);
        System.out.println("rs = " + rs);
        //5.获取集合的长度
        System.out.println("list.size() = " + list.size());
        //6.删除集合中指定索引位置的元素，并返回被删除的元素
        System.out.println("list.remove(1) = " + list.remove(1));
        System.out.println("list = " + list);
        //7.删除集合中指定元素，并返回删除成功与否的boolean值
        System.out.println("list.remove(\"javaee\") = " + list.remove("javaee"));
        System.out.println("list = " + list);
        //8.删除集合中指定元素，并返回删除成功与否的boolean值
        System.out.println("list.remove(\"hello\") = " + list.remove("hello"));
        System.out.println("list = " + list);
        //9.修改集合中指定索引位置的元素，并返回被修改的元素
        list.set(1,"javaee");
        System.out.println("list = " + list);

    }
}
